package subscriberPanels;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import librarianPanels.SearchABookPanel;
import javax.swing.JButton;

import clientGUI.MainGUI;

import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class OrderBookPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Create the panel.
	 */
	public OrderBookPanel() {
		SearchABookPanel x=new SearchABookPanel();
		x.setBounds(new Rectangle(0, 0, 644, 462));
		setPreferredSize(x.getPreferredSize());
		setLayout(null);
		add(x);
		
		JButton btnNewButton = new JButton("Order");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (SearchABookPanel.table.getSelectedRow() != -1) {
					String temp = SearchABookPanel.table
							.getModel()
							.getValueAt(
									SearchABookPanel.table.getSelectedRow(), 5)
							.toString();
					if (temp.contentEquals("N/A")) {
						JOptionPane.showMessageDialog(new JFrame(),
								"Book avilable on shelf!", "Error",
								JOptionPane.ERROR_MESSAGE);
						} 
					else 
					{
						String msg[]=new String[3];
						msg[0]="OrderBook";
						msg[1]=MainGUI.OBLClient.ClientID;
						msg[2]=SearchABookPanel.table.getModel().getValueAt(SearchABookPanel.table.getSelectedRow(),0).toString();
						MainGUI.OBLClient.handleMessageFromClient(msg);
					}
				}
				else
				{
					JOptionPane.showMessageDialog(new JFrame(),	"ERROR - Nothing selected!","Error",JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btnNewButton.setBounds(431, 385, 138, 47);
		x.add(btnNewButton);
		x.remove(x.background);
		x.add(x.background);
	}
}
